<template>
  <d-scroll-view  @refresherrefresh="getDetail" :refresher-triggered="triggered">
    <proj-detail-layout :process-instance-id="processInstanceId" :project-number="projectNumber">
    <d-forms label-width="200rpx">
      <d-forms-item label="最终用户">
        <pm-custom-select disabled :custom-id="form.endUserId"></pm-custom-select>
      </d-forms-item>
      <d-forms-item label="合同用户">
        <pm-custom-select disabled :custom-id="form.endUserId"></pm-custom-select>
      </d-forms-item>
      <d-forms-item label="销售经理">
        <pm-user-select disabled :user-id="form.salesManager"></pm-user-select>
      </d-forms-item>
      <d-forms-item label="项目属性" :type="DFormInputType.DICT" :input="form.projectAttribute" :dict-type="PM_DICT_TYPE.PROJECT_ATTRIBUTE"></d-forms-item>
      <d-forms-item label="售前工程师">
        <pm-user-select disabled :user-id="form.preSales"></pm-user-select>
      </d-forms-item>
      <d-forms-item label="商务负责人">
        <pm-user-select disabled :user-id="form.businessManager"></pm-user-select>
      </d-forms-item>
      <d-forms-item label="相关资料">
        <text class="link-text">《项目基础信息表》</text>
        <text class="link-text">《客户信息表》</text>
        <text class="link-text">《项目推进表》</text>
      </d-forms-item>
      <d-forms-item label="申请理由" :input="form.applicationReasons"></d-forms-item>
    </d-forms>
  </proj-detail-layout>
  </d-scroll-view>
</template>

<script setup lang="ts">
import ProjDetailLayout from "@/components/ProjDetailLayout/index.vue";
import {useProjectApplyApi} from "@/api/pm/project/projectApply";
import {PM_DICT_TYPE} from "@/utils/pmDict";
import {DFormInputType} from "@/utils/enum";

defineOptions({ name: 'ProjectApply' })

const projectNumber = ref<string>(null);
const processInstanceId = ref<string>(null);
const initForm = {
  projectType: null,
  projectAttribute: null,
  projectName: null,
  salesManager: null,
  applicationReasons: null,
  preSales: null,
  result: null,
  userId: null,
  projectGrade: null,
  projectNumber: null,
  contractUserId: null,
  endUserId: null,
  storaged: null,
  businessManager: null,
  id: null,
  resultCause: null,
  processInstanceId: null,
}
const form = ref<ProjApplyForm>(initForm);
const triggered = ref<boolean>(false);
function getDetail() {
  if (projectNumber.value) {
    triggered.value = true;
    useProjectApplyApi().getFoundProjByProjNum(projectNumber.value).then((res) => {
      if (res.code === 0 && res.data) {
        form.value = res.data;
      }
    }).finally(() => {
      triggered.value = false;
    })
  }
}

onLoad((query) => {
  projectNumber.value = query['project_number']
  processInstanceId.value = query['process_instance_id']
  getDetail();
})
</script>

<style scoped lang="scss">

</style>
